package com.tm.dk.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tm.dk.dto.MonitorDTO;
import com.tm.dk.service.MonitorService;
import com.tm.entity.MonitorEntity;
import com.tm.exception.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("monitor/setting")
public class MonitorController {

    @Autowired
    private MonitorService monitorService;




    /***
     * * 分页条件查询
     *
     */

    @PostMapping("/list")
    public Result list(@RequestParam(required = false,defaultValue = "1") Integer page,
                       @RequestParam(required = false,defaultValue = "1") Integer pageSize,

            @RequestBody MonitorEntity monitorEntity) {

        Page<MonitorEntity> monitor = monitorService.pageList(page,pageSize,monitorEntity);

        return Result.success(monitor);

    }

    /**
     * 新增
     * @param monitorEntity
     * @return
     */
    @PostMapping("save")
    public Result save(@RequestBody MonitorEntity monitorEntity){
        monitorService.save(monitorEntity);
        return Result.success();
    }

    /**
     * 修改
     * @param monitor
     * @return
     */

    @PutMapping ("/update")
    public Result update(@RequestBody MonitorEntity monitor) {
        monitorService.updateById(monitor);

        return Result.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public Result delete(String id) {
        monitorService.removeById(id);
        return Result.success();
    }


}
